Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idl: Disallow empty discriminators #3166

Merged

Conversation

acheroncrypto
Copy link
Collaborator

Problem

It's possible to set the discriminators to an empty array. For example:

#[account(discriminator = [])]
pub struct MyAccount {}

This shouldn't be allowed due to security and convenience reasons.

Summary of changes

Disallow empty discriminators during IDL generation.

The reason for handling this during IDL build process is because we can't reliably get the discriminator from parsing the input (e.g. discriminator = EMPTY is also valid).

And the reason for not implementing our own custom discriminator type e.g.

pub struct NonZeroDiscriminator(&'static [u8]);

is because it would not allow using programs that don't have discriminators (e.g. some of the SPL programs).


Note: This PR is part of a greater effort explained in #3097.

Copy link

vercel bot commented Aug 12, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added lang idl related to the IDL, either program or client side feature labels Aug 12, 2024
@acheroncrypto acheroncrypto mentioned this pull request Aug 12, 2024
26 tasks
@acheroncrypto acheroncrypto merged commit 85ebc33 into coral-xyz:master Aug 12, 2024
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature idl related to the IDL, either program or client side lang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant